<?php
class MyRedis
{
    private static $handler;

    private static function handler()
    {
        if (!self::$handler) {
            self::$handler = new \Redis();
            self::$handler->pconnect('127.0.0.1', '6379');
        }
        return self::$handler;
    }

    public static function get($key)
    {
        $value = self::handler()->get($key);
        $value_serl = @unserialize($value);
        if (is_object($value_serl) || is_array($value_serl)) {
            return $value_serl;
        }
        return $value;
    }
    public static function expire($key, $sec)
    {
        $value =self::$handler()->expire($key,$sec);
        return "";
    }
    public static function set($key, $value)
    {
        if (is_object($value) || is_array($value)) {
            $value = serialize($value);
        }
        return self::handler()->set($key, $value);
    }
    public static function delete($key)
    {
        return self::handler()->delete($key);
    }
    public static function rpush($key, $value)
    {
        return self::handler()->rpush($key, $value);
    }
    public static function lpop($key)
    {
        return self::handler()->lpop($key);
    }
    public static function lget($key, $index = 0)
    {
        return self::handler()->lget($key, $index);
    }
    public static function lgetrange($key)
    {
        return self::handler()->lgetrange($key, 0, -1);
    }

    public static function lRem($key, $val, $count)
    {
        return self::handler()->lRem($key, $val, $count);
    }
    public static function lLen($key)
    {
        return self::handler()->lLen($key);
    }
    public static function setListByLen($key,$len)
    {
        for($i = 0;$i < $len; $i++){
            self::rpush($key,1);
        }
    }

    public static function rolldian($key){
        self::delete($key);
        $dianlist = [];
        for ($i=1; $i <= 100; $i++) { 
            $dianlist[] = $i;
        }
        shuffle($dianlist);
        foreach ($dianlist as $value) {
           self::rpush($key,$value);
        } 
    }



}